<?php
/************************************************************************
 Omnitrix - PHP Development Framework
 Copyright (C) 2012-2018 amonest(eastson@outlook.com)

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
************************************************************************/

define('OMNITRIX_INDEX',		'http://www.cnblogs.com/eastson/');
define('OMNITRIX_FORUM',		'http://www.cnblogs.com/eastson/');
define('OMNITRIX_WIKI',			'http://www.cnblogs.com/eastson/');
define('OMNITRIX_LATEST',		'http://www.cnblogs.com/eastson/');
define('OMNITRIX_VERSION',		'0.3.178');

function otx_import_class($class_name)
{
	if (substr($class_name, 0, 9) == 'omnitrix_') {
		$tokens = explode('_', $class_name);
		if (count($tokens) == 2) {
			$class_file = DIR_SYSTEM . 'includes/class_' . $tokens[1] . '.php';
		} else {
			$class_file = DIR_SYSTEM . 'includes/' . substr($class_name, 9) . '.php';
		}

		if (is_file($class_file)) {
			include_once $class_file;

			if (class_exists($class_name, false) || interface_exists($class_name, false)) {
				return true;
			}
		}
	}
}

function otx_import_functions($functions_name)
{
	static $loaded_functions = array();

	foreach (func_get_args() as $functions_name) {
		if (empty($loaded_functions[$functions_name])) {
			$functions_file = DIR_SYSTEM . 'includes/functions_' . $functions_name . '.php';
			if (!file_exists($functions_file)) {
				throw new Exception('Functions file not exists: ' . $functions_file);
			}

			include_once $functions_file;
			$loaded_functions[$functions_name] = $functions_file;
		}
	}
}